<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>

<body>

<form id="myform"  method="post" action="#">
	<input type="text" size="25" maxlength="50" value="123456">
</form>


<script>

var form = document.getElementById("myform");
var field1 = form.elements[0];

var getClipboardText = function(event){
	var clipboardData =  (event.clipboardData || window.clipboardData);
	return clipboardData.getData("text");
}
var  setClipboardText = function(event, value){
	if (event.clipboardData){
		event.clipboardData.setData("text/plain", value);
	} else if (window.clipboardData){
		window.clipboardData.setData("text", value);
	}
}


var  addHandler = function(element, type, handler){
	if (element.addEventListener){
		element.addEventListener(type, handler, false);
	} else if (element.attachEvent){
		element.attachEvent("on" + type, handler);
	} else {
		element["on" + type] = handler;
	}
}

addHandler(field1, "paste", function(event){
	event = event || window.event;
	var text =  getClipboardText(event);
	if (!/^\d*$/.test(text)){
        if (event.preventDefault){
            event.preventDefault();
        } else {
            event.returnValue = false;
        }
	}
})

</script>

</body>
</html>
